// 用户管理模块接口
import request from "@/utils/request";
import {
  UserResponseData,
  User,
  AllRoleResponseData,
  SetRoleData,
} from "./type";

// 枚举地址
enum API {
  // 获取全部已有用户账号信息
  ALLUSER_URL = "/admin/acl/user/",
  // 新增用户
  ADDUSER_URL = "/admin/acl/user/save",
  // 修改用户
  UPDATEUSER_URL = "/admin/acl/user/update",
  // 获取全部职位,当前账号拥有的职位接口
  ALLROLE_URL = "/admin/acl/user/toAssign/",
  //   给已有的用户分配角色接口
  SETROLE_URL = "/admin/acl/user/doAssignRole",
  //删除某一个账号
  DELETEUSER_URL = "/admin/acl/user/remove/",
  // 批量删除
  DELETEALLUSER_URL = "/admin/acl/user/batchRemove",
}

// 获取全部已有用户账号信息
export const reqUserInfo = (page: number, limit: number, username: string) =>
  request.get<any, UserResponseData>(
    API.ALLUSER_URL + `${page}/${limit}/?username=${username}`
  );

// 新增用户或者修改用户
export const reqAddOrUpdateUser = (data: User) => {
  if (data.id) {
    // 修改用户
    return request.put<any, any>(API.UPDATEUSER_URL, data);
  } else {
    // 新增用户
    return request.post<any, any>(API.ADDUSER_URL, data);
  }
};

// 获取全部职位,当前账号拥有的职位接口
export const reqAllRole = (userId: number) =>
  request.get<any, AllRoleResponseData>(API.ALLROLE_URL + userId);

// 给已有的用户分配角色接口
export const reqSetUserRole = (data: SetRoleData) =>
  request.post<any, any>(API.SETROLE_URL, data);

// 删除某一个账号
export const reqRemoveUser = (userId: number) =>
  request.delete<any, any>(API.DELETEUSER_URL + userId);

// 批量删除
export const reqSelectUser = (idList: number[]) =>
  request.delete<any, any>(API.DELETEALLUSER_URL, { data: idList });
